#include <iostream>
#include <queue>
using namespace std;
#define MVNum 50
typedef struct
{
    bool visited[MVNum];//辅助数组
    int  arcs[MVNum][MVNum];//领接矩阵
    int  n;//
}AMGraph;//领接矩阵的结构体

AMGraph G;
queue<int>Q;


void BFSTraverse(int v, int n)
{//v是输入的数从什么开始遍历
    cout << v << " ";
    G.visited[v] = true;
    Q.push(v);
    int front;
    while (!Q.empty())
    {
        front = Q.front();//输出队头元素
        Q.pop();//弹出队头元素
        for (int i = 0; i < n; i++)
        {
            if (G.arcs[front][i] != 0 && G.visited[i] == false)
            {
                cout << i << " ";
                G.visited[i] = true;
                Q.push(i);
            }
        }
    }
}

int main()
{
    cin >> G.n;
    for (int i = 0; i < G.n; i++)
    {
        G.visited[i] = false;
        for (int j = 0; j < G.n; j++)
        {
            cin>>G.arcs[i][j];
        }
    }
    BFSTraverse(0, G.n);
    return 0;
}